package com.abing.observer.test1.subject.impl;

import com.abing.observer.test1.observer.ObServer;
import com.abing.observer.test1.subject.AbstractSubject;

import java.util.ArrayList;
import java.util.List;

public class WeChatSubject implements AbstractSubject {

    /**
     * 存放主题的集合
     */
    private List<ObServer> obServerList = new ArrayList<ObServer>();
    @Override
    public void addObServer(ObServer obServer) {
        obServerList.add(obServer);

    }

    /**
     * 删除
     * @param obServer
     */
    @Override
    public void removeServer(ObServer obServer) {
        obServerList.remove(obServer);
    }

    /**
     * 遍历，通知
     * @param message
     */
    @Override
    public void notifyObServer(String message) {
        for (ObServer obServer:obServerList){
            obServer.update(message);
        }
    }
}
